const videocall = {
  state: {
    userID:'',
    userSig: '',
    sdkAppId: 0,
    videoRoom: 0,
    videoCallStatus: 0, // 默认空闲状态，VIDEO_CALL_STATUS_FREE = 0
    videoCallUserList: [] // 群视频通话成员列表
  },
  mutations: {
    generateVideoRoom(state, videoRoom) { // 初始化房间号
      if (videoRoom) {
          state.videoRoom = videoRoom;
      } else {
        // state.videoRoom = 233;
        state.videoRoom = Math.ceil(Math.random() * (2 ** 32 - 1));
      }
    },
    toggleVideoCallStatus(state, videoCallStatus){
      state.videoCallStatus = typeof videoCallStatus === 'undefined' ? 0 : videoCallStatus;
    },
    updateUserInfo(state, options){
      // 登录成功后，更新用户信息，以便实时音视频初始化等操作
      state.userID = options.userID;
      state.userSig = options.userSig;
      state.sdkAppId = options.sdkAppId;
    },
    addedVideoCallUser(state, userID){
      if(state.videoCallUserList.indexOf(userID) === -1){
        state.videoCallUserList.push(userID);
      }
    },
    removedVideoCallUser(state, userID){
      if(state.videoCallUserList.indexOf(userID) > -1){
        state.videoCallUserList.splice(state.videoCallUserList.indexOf(userID),1);
      }
    },
    resetVideoCallUserList(state){
      state.videoCallUserList = [];
    },
    reset(state) {
      Object.assign(state, {
        userID: '',
        userSig: '',
        sdkAppId: 0,
        videoRoom: 0,
        videoCallStatus: 0,
        videoCallUserList: []
      });
    }
  }
}

export default videocall;